package com.cms.action;

import java.io.Serializable;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.cms.base.Pagination;
import com.cms.entity.Channel;
import com.cms.service.ChannelService;
import com.cms.util.CommonUtils;
import com.opensymphony.xwork2.ActionSupport;

public class ChannelAction extends ActionSupport {
	
	private int maxResults = 10;
	private int firstResult = 0;
	
	private int id;

	private List<Serializable> ids;
	
	private ChannelService channelService;
	
	private Channel channel;
	
	List<Channel> channelList;
	
	Pagination<Channel> pagination;
	
	
	
	@Override
	public String execute(){
		String offset = ServletActionContext.getRequest().getParameter("pager.offset");
		if(CommonUtils.isNotEmpty(offset))
			firstResult = Integer.valueOf(offset);
		pagination = channelService.queryAllChannels(channel, firstResult, maxResults);
		return SUCCESS;
	}
	
	public String toSave(){
		return "toSave";
	}
	
	public String save(){
		channelService.save(channel);
		return "save";
	}

	public String toUpdate(){
		channel = channelService.get(id);
		return "toUpdate";
	}
	
	public String update(){
		channelService.update(channel);
		return "update";
	}
	
	public String delete(){
		channelService.delete(ids);
		return "delete";
	}
	
	public String get(){
		channel = channelService.get(id);
		return "get";
	}

	
	
	
	
	public ChannelService getChannelService() {
		return channelService;
	}
	public void setChannelService(ChannelService channelService) {
		this.channelService = channelService;
	}


	public Channel getChannel() {
		return channel;
	}
	public void setChannel(Channel channel) {
		this.channel = channel;
	}

	public List<Channel> getChannelList() {
		return channelList;
	}
	public void setChannelList(List<Channel> channelList) {
		this.channelList = channelList;
	}

	public Pagination<Channel> getPagination() {
		return pagination;
	}
	public void setPagination(Pagination<Channel> pagination) {
		this.pagination = pagination;
	}

	public int getMaxResults() {
		return maxResults;
	}
	public void setMaxResults(int maxResults) {
		this.maxResults = maxResults;
	}

	public int getFirstResult() {
		return firstResult;
	}
	public void setFirstResult(int firstResult) {
		this.firstResult = firstResult;
	}

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}

	public List<Serializable> getIds() {
		return ids;
	}
	public void setIds(List<Serializable> ids) {
		this.ids = ids;
	}

	
}
